class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        count = dict()
        for i in range(len(nums)):
            # print(count.keys())
            if nums[i] not in count.keys():
                count[nums[i]] = 1
            else:
                count[nums[i]] += 1
        for key, value in count.items():
            if value > len(nums)//2:
                return key




class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        res = dict()
        if len(nums) == 1:
            return nums[0]
        for num in nums:
            if num in res:
                res[num] += 1
                if res[num] > len(nums)//2:
                    return num
            else:
                res[num] = 1